<?php

class News extends Controller {

	function News(){
		parent::Controller();
		$this->common_model->checklogin();
		$this->load->model('news_model');
	}
	function addnew($code){
		$this->news_model->addnew($code);
		$this->_loadview_addnew($code);
	}
	function delete(){
		$code = $this->news_model->delete();
		redirect('news/loadview/'.$code);
	}
	function update($id=''){
		$code = $this->news_model->update();
		$this->_loadview_update($id);
	}
	function loadview($code){
		$parentid=$this->news_model->code2id($code);
		$data = $this->common_model->general();
		$data['bodyview'] = 'news/list';
		$data['method_code']=$code;
		$data['datagrid'] = $this->news_model->getdatasource($parentid);
		$this->load->view('mastertemplate',$data);
	}
	function _loadview_addnew($code){
		$data = $this->common_model->general();
		$parentid=$this->news_model->code2id($code);
		$data['show_category'] = $code == 'tuyen_dung'?'0':'1';
		$data['show_image'] = $code == 'thong_tin_phap_ly' || $code == 'dich_vu' || $code == 'tuyen_dung' ?'0':'1';
		$data['show_summary'] = $code == 'dich_vu' || $code == 'tuyen_dung' ?'0':'1';
		$data['code'] = $code;
		$data['bodyview'] = 'news/addnew';
		$data['category'] = $this->news_model->getcategorylist($parentid);
		$this->load->view('mastertemplate',$data);
	}
	function _loadview_update($id){
		$cateid = $this->news_model->get_category_by_news_id($id);
		$parentid=$this->news_model->get_parentid($cateid);
		$data = $this->common_model->general();
		$code = $this->news_model->id2code($id);
		$data['code']=$code;
		$data['show_category'] = $code == 'tuyen_dung'?'0':'1';
		$data['show_image'] = $code == 'thong_tin_phap_ly' ||  $code == 'dich_vu' || $code == 'tuyen_dung' ?'0':'1';
		$data['show_summary'] = $code == 'dich_vu' || $code == 'tuyen_dung' ?'0':'1';
		$data['bodyview'] = 'news/update';	
		$res = $this->news_model->getdetail($id);
		if(FALSE===$res) redirect('news','location');
		$data['detail'] = $res;
		$data['category'] = $this->news_model->getcategorylist($parentid);
		$this->load->view('mastertemplate',$data);
	}
}

/* End of file */